package com.cloudlinkscm.base.filecenter.client.service;

import com.cloudlinkscm.base.filecenter.client.config.FileCenterFeignClientConfiguration;
import com.cloudlinkscm.base.filecenter.constant.FileCenterService;
import com.cloudlinkscm.base.filecenter.service.FileRemoteService;
import com.cloudlinkscm.loms.framework.core.pojo.RestfulApiResponse;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author : tac
 * @date : 2017/7/26
 */

@FeignClient(name = FileCenterService.SERVICE_NAME, path = FileRemoteService.PATH, fallback = FileService.HystrixFallbackService.class, configuration = FileCenterFeignClientConfiguration.class)
public interface FileService {
    @RequestMapping(value = "url/documents", method = RequestMethod.GET)
    RestfulApiResponse<Map<String, String>> documentUrls(@RequestParam Map<String, Object> dto);

    @RequestMapping(value = "url/images", method = RequestMethod.GET)
    RestfulApiResponse<Map<String, String>> imageUrls(@RequestParam Map<String, Object> dto);

    @RequestMapping(value = "upload/document", method = RequestMethod.PUT)
    RestfulApiResponse<String> uploadDocument(MultipartFile file, @RequestParam Map<String, Object> dto);

    @RequestMapping(value = "upload/image", method = RequestMethod.PUT)
    RestfulApiResponse<String> uploadImage(MultipartFile file, @RequestParam Map<String, Object> dto);

    @RequestMapping(value = "delete", method = RequestMethod.DELETE)
    RestfulApiResponse<Integer> delete(@RequestParam Map<String, Object> dto);

    @Component
    class HystrixFallbackService implements FileService {
        @Override
        public RestfulApiResponse<Map<String, String>> documentUrls(@RequestParam Map<String, Object> dto) {
            return null;
        }

        @Override
        public RestfulApiResponse<Map<String, String>> imageUrls(@RequestParam Map<String, Object> dto) {
            return null;
        }

        @Override
        public RestfulApiResponse<String> uploadDocument(MultipartFile file, @RequestParam Map<String, Object> dto) {
            return null;
        }

        @Override
        public RestfulApiResponse<String> uploadImage(MultipartFile file, @RequestParam Map<String, Object> dto) {
            return null;
        }

        @Override
        public RestfulApiResponse<Integer> delete(@RequestParam Map<String, Object> dto) {
            return null;
        }
    }
}
